HG19=http://hgdownload.cse.ucsc.edu/goldenPath/hg19
TABIX=${HOME}/package/tabix-0.2.5
SAMTOOLS=${HOME}/package/samtools-0.1.18

%.fa.fai: %.fa
	${SAMTOOLS}/samtools faidx $<

all:    hg19 \
	hg19/hg19.fa.fai \
	hg19/stsMap.txt.gz \
	hg19/snp132.txt.gz \
	hg19/cytoBand.txt.gz \
	hg19/refGene.txt.gz

hg19:
	mkdir -p $@

hg19/hg19.fa:
	curl -s "${HG19}/chromosomes/chr22.fa.gz" |\
		gunzip -c > $@
	
hg19/stsMap.txt.gz:
	curl -s "${HG19}/database/stsMap.txt.gz" |\
		gunzip -c |\
		sort -t '	' -k1,1 -k2,2n -k3,3n  > hg19/stsMap.txt
	${TABIX}/bgzip  hg19/stsMap.txt
	${TABIX}/tabix -f -s 1 -b 2 -e 3 $@

hg19/snp132.txt.gz :
	curl -s "${HG19}/database/snp132.txt.gz" |\
		gunzip -c |\
		awk -F '	' '($$2=="chr22")' |\
		sort -t '	' -k2,2 -k3,3n -k4,4n  > hg19/snp132.txt
	${TABIX}/bgzip  hg19/snp132.txt
	${TABIX}/tabix -f -s 2 -b 3 -e 4 $@

hg19/cytoBand.txt.gz:
	curl -s "${HG19}/database/cytoBand.txt.gz" |\
		gunzip -c |\
		sort -t '	' -k1,1 -k2,2n -k3,3n  > hg19/cytoBand.txt
	${TABIX}/bgzip  hg19/cytoBand.txt
	${TABIX}/tabix -f -s 1 -b 2 -e 3  $@


hg19/refGene.txt.gz:
	curl -s "${HG19}/database/refGene.txt.gz" |\
		gunzip -c |\
		sort -t '	' -k3,3 -k5,5n -k6,6n  > hg19/refGene.txt
	${TABIX}/bgzip  hg19/refGene.txt
	${TABIX}/tabix -f -s 3 -b 5 -e 6  $@

